﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Reviewer.Entities.Services;
using Reviewer.Business;
using Reviewer.Entities;
using AjaxControlToolkit;
using System.IO;

public partial class CMSV2_GameManager : System.Web.UI.Page
{
    public Guid GameId
    {
        get
        {
            if (ViewState["GameId"] != null)
            {
                return (Guid)ViewState["GameId"];
            }

            return Guid.Empty;
        }
        set
        {
            ViewState["GameId"] = value;
            this.uiGameInfo.GameId = value;
            this.uiGtiTopImage.GameId = value;
            this.uiGsScreenshots.GameId = value;
            this.uiGcGameConvers.GameId = value;
            this.uiGvGameVideo.GameId = value;
            this.uiGpGamePegi.GameId = value;
            this.uiGfGameFactsheet.GameId = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Guid gameId = Guid.Empty;
            if (!String.IsNullOrEmpty(Request["GameId"]))
            {
                try
                {
                    gameId = new Guid(Request["GameId"]);
                }
                catch { }
            }
            this.GameId = gameId;

            this.uiMvGame.ActiveViewIndex = 0;
            ResetMenu();
            this.uiGameInfo.Refresh();
            this.uiGfGameFactsheet.GameId = this.GameId;
            this.uiGfGameFactsheet.LoadData();
        }

        this.uiGameInfo.GameId = this.GameId;
        this.uiGtiTopImage.GameId = this.GameId;
        this.uiGsScreenshots.GameId = this.GameId;
        this.uiGcGameConvers.GameId = this.GameId;
        this.uiGvGameVideo.GameId = this.GameId;
        this.uiGpGamePegi.GameId = this.GameId;
        this.uiGfGameFactsheet.GameId = this.GameId;
    }

    protected void mnuGame_MenuItemClick(object sender, MenuEventArgs e)
    {
        int index = 0;
        if (Int32.TryParse(e.Item.Value, out index))
        {
            uiMvGame.ActiveViewIndex = index;
        }
    }
    protected void mvGame_ActiveViewChanged(object sender, EventArgs e)
    {
        switch (uiMvGame.ActiveViewIndex)
        {
            case 2: //covers
                uiGcGameConvers.Formats = this.uiGameInfo.SelectedFormats();
                break;
            case 3: //screenshots
                uiGsScreenshots.Formats = this.uiGameInfo.SelectedFormats();
                uiGsScreenshots.Refresh();
                break;
            case 4:
                break;
            case 5:
                uiGpGamePegi.Formats = this.uiGameInfo.SelectedFormats();
                break;
            case 6:
                break;
        }
    }

    private void ResetMenu()
    {
        foreach (MenuItem item in this.uiMnuGame.Items)
        {
            item.Enabled = this.GameId.Equals(Guid.Empty) ? item.Value.Equals("0") ? true : false : true;
        }
    }
}
